package com.qfedu.fmmall.config;

import com.qfedu.fmmall.interceptor.CheckTokenInterceptor;
import com.qfedu.fmmall.interceptor.SetTimeInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @author : yanBin
 * @date :2021/12/14 11:50
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Resource
    private CheckTokenInterceptor checkTokenInterceptor;

    @Autowired
    private SetTimeInterceptor setTimeInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(checkTokenInterceptor)
                 .addPathPatterns("/shopcart/**")
                 .addPathPatterns("/order/**")
                 .excludePathPatterns("/user/**")
                 .addPathPatterns("/user/check");

        registry.addInterceptor(setTimeInterceptor).addPathPatterns("/**").         //表示拦截的接口
                excludePathPatterns("/user/login");                                 //表示放行的接口
    }
}
